﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DotNetX
{
    /// <summary>
    /// This manages different countries
    /// </summary>
    public class Country
    {
        /// <summary>
        /// The name of this country
        /// </summary>
        public string Name
        {
            get
            {
                // return the name
                return this._name;
            }
            set
            {
                // set the name
                this._name = value;
            }
        }
        private string _name = string.Empty;

        /// <summary>
        /// The abbrieviation of this country
        /// </summary>
        /// <remarks>E.G. GB, U.S.A.</remarks>
        public string Abbrieviation
        {
            get
            {
                // return the abbrieviation
                return this._abbrieviation;
            }
            set
            {
                // set the abbrieviation
                this._abbrieviation = value;
            }
        }
        private string _abbrieviation = string.Empty;

        /// <summary>
        /// The currency code
        /// </summary>
        /// <remarks>E.G. GBP, USD</remarks>
        public string CurrencyCode
        {
            get
            {
                // return the currency code
                return this._currencyCode;
            }
            set
            {
                // set the currency code
                this._currencyCode = value;
            }
        }
        private string _currencyCode = string.Empty;

        /// <summary>
        /// The currency symbol
        /// </summary>
        /// <remarks>E.G. £, $</remarks>
        public string CurrencySymbol
        {
            get
            {
                // return the currency symbol
                return this._currencySymbol;
            }
            set
            {
                // set the currency symbol
                this._currencySymbol = value;
            }
        }
        private string _currencySymbol = string.Empty;

        /// <summary>
        /// The country phone code
        /// </summary>
        /// <remarks>E.G. for the UK - 44</remarks>
        public int PhoneCode
        {
            get
            {
                // return the phone code
                return this._phoneCode;
            }
            set
            {
                // set the phone code
                this._phoneCode = value;
            }
        }
        private int _phoneCode = 0;

        /// <summary>
        /// The phone number format
        /// </summary>
        /// <remarks>All spaces will be removed from the checked phone number
        /// The format is like (XXXXX)-XXXXXX</remarks>
        public string PhoneNumberFormat
        {
            get
            {
                // return the phone number format
                return this._phoneNumberFormat;
            }
            set
            {
                // set the phone number format
                this._phoneNumberFormat = value;
            }
        }
        private string _phoneNumberFormat = string.Empty;

        /// <summary>
        /// The postal code format
        /// </summary>
        /// <remarks>All spaces will be removed from the checked postal code
        /// The format is like XXXXX</remarks>
        public string PostalCodeFormat
        {
            get
            {
                // return the postal code format
                return this._postalCodeFormat;
            }
            set
            {
                // set the postal code format
                this._postalCodeFormat = value;
            }
        }
        private string _postalCodeFormat = string.Empty;

        /// <summary>
        /// Constructs a country
        /// </summary>
        /// <param name="name">The name of the country</param>
        /// <param name="abbrieviation">The country abbrieviation e.g. GB, U.S.A.</param>
        /// <param name="currencyCode">The currency code used for the country</param>
        /// <param name="currencySymbol">The currency symbol used for the country</param>
        public Country(string name, string abbrieviation, string currencyCode, string currencySymbol, int phoneCode, string phoneNumberFormat, string postalCodeFormat)
        {
            if (name == null)
                throw new ArgumentNullException("'name' is null.");
            if (name.Length == 0)
                throw new ArgumentOutOfRangeException("'name' is zero-length.");
            if (abbrieviation == null)
                throw new ArgumentNullException("'abbrieviation' is null.");
            if (abbrieviation.Length == 0)
                throw new ArgumentOutOfRangeException("'abbrieviation' is zero-length.");
            if (currencyCode == null)
                throw new ArgumentNullException("'currencyCode' is null.");
            if (currencyCode.Length == 0)
                throw new ArgumentOutOfRangeException("'currencyCode' is zero-length.");
            if (currencySymbol == null)
                throw new ArgumentNullException("'currencySymbol' is null.");
            if (currencySymbol.Length == 0)
                throw new ArgumentOutOfRangeException("'currencySymbol' is zero-length.");
            if (phoneNumberFormat == null)
                throw new ArgumentNullException("'phoneNumberFormat' is null.");
            if (phoneNumberFormat.Length == 0)
                throw new ArgumentOutOfRangeException("'phoneNumberFormat' is zero-length.");
            if (postalCodeFormat == null)
                throw new ArgumentNullException("'postalCodeFormat' is null.");
            if (postalCodeFormat.Length == 0)
                throw new ArgumentOutOfRangeException("'postalCodeFormat' is zero-length.");

            // set the values
            this.Name = name;
            this.Abbrieviation = abbrieviation;
            this.CurrencyCode = currencyCode;
            this.CurrencySymbol = currencySymbol;
            this.PhoneCode = phoneCode;
            this.PhoneNumberFormat = phoneNumberFormat;
            this.PostalCodeFormat = postalCodeFormat;
        }

        #region Validation

        /// <summary>
        /// This validates the passed phone number
        /// </summary>
        /// <param name="phoneNumber">The phone number to validate</param>
        /// <param name="country">The country to validate the phone number against</param>
        /// <returns>True if the phone number is valid, else false</returns>
        public static bool ValidatePhoneNumber(string phoneNumber, string country)
        {
            if (phoneNumber == null)
                throw new ArgumentNullException("'phoneNumber' is null.");
            if (phoneNumber.Length == 0)
                throw new ArgumentOutOfRangeException("'phoneNumber' is zero-length.");
            if (country == null)
                throw new ArgumentNullException("'country' is null.");
            if (country.Length == 0)
                throw new ArgumentOutOfRangeException("'country' is zero-length.");

            // TODO: this method
            return true;
        }

        /// <summary>
        /// This validates the passed Skype phone number against the passed country
        /// </summary>
        /// <param name="skypePhoneNumber">The Skype phone number to validate</param>
        /// <param name="country">The country to validate the Skype phone number against</param>
        /// <returns>True if the Skype phone number is valid, else false</returns>
        public static bool ValidateSkypePhoneNumber(string skypePhoneNumber, string country)
        {
            if (skypePhoneNumber == null)
                throw new ArgumentNullException("'skypePhoneNumber' is null.");
            if (skypePhoneNumber.Length == 0)
                throw new ArgumentOutOfRangeException("'skypePhoneNumber' is zero-length.");
            if (country == null)
                throw new ArgumentNullException("'country' is null.");
            if (country.Length == 0)
                throw new ArgumentOutOfRangeException("'country' is zero-length.");

            // TODO this method
            return true;
        }

        /// <summary>
        /// This validates the passed postal code against the passed country
        /// </summary>
        /// <param name="postalCode">The postal code to validate</param>
        /// <param name="country">The country to validate the postal code against</param>
        /// <returns>True if the postal code is valid, else false</returns>
        public static bool ValidatePostalCode(string postalCode, string country)
        {
            if (postalCode == null)
                throw new ArgumentNullException("'postalCode' is null.");
            if (postalCode.Length == 0)
                throw new ArgumentOutOfRangeException("'postalCode' is zero-length.");
            if (country == null)
                throw new ArgumentNullException("'country' is null.");
            if (country.Length == 0)
                throw new ArgumentOutOfRangeException("'country' is zero-length.");

            //TODO This method
            return true;
        }

        #endregion
    }
}
